package com.lilihub.miaosha.controller;

import com.lilihub.miaosha.common.CodeMsg;
import com.lilihub.miaosha.common.Result;
import com.lilihub.miaosha.service.MiaoshaUserService;
import com.lilihub.miaosha.util.ValidateUtil;
import com.lilihub.miaosha.vo.LoginVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;


@Controller
@RequestMapping("/login")
public class LoginController {


    @Autowired
    private MiaoshaUserService miaoshaUserService;


    @RequestMapping("/to_login")
    public String toLogin(){
        return "login";
    }



    @ResponseBody
    @RequestMapping("/do_login")
    public Result doLogin(@Valid LoginVo loginVo,
                          HttpServletResponse response){

        System.out.println(loginVo);

        //登录
       String token = miaoshaUserService.login(loginVo,response);

       return Result.success(token);

    }





}
